function outmat = f2m(name,s)
% Read *.dat binary file from FORTRAN into MatLab workspace
% 
% Input:  "name"  : name of the *.dat file entered as string, e.g. name='test.dat'  
%         "s"     : vector containing the number of states of each state
%                   variable
% Output: "outmat": numerical array of *.dat entries
%
% last modified: 18/09/2014
% Thomas Siemsen

    fileID=fopen(name);
    u=size(str2num(fgetl(fileID)),2);
    fclose(fileID);
    fid=fopen(name,'r');
    C=textscan(fid, [repmat('%f',[1,u]) '%[^\n\r]'], 'Delimiter', '', 'WhiteSpace', '',  'ReturnOnError', false);
    C=C(:,1:end-1);
    C=cat(2,C{:});
    if length(s)==1
    outmat=C;
    else
    outmat=reshape(C,s);
    end
    fclose(fid);
end